package lumingweihua.future.cn.lumingweihua.widget.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zhusx.core.adapter.Lib_BaseAdapter;
import com.zhusx.core.app.Lib_BaseDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lumingweihua.future.cn.lumingweihua.R;

/**
 * Created by z1986 on 2018/3/15.
 */
public class BottomListDialog extends Lib_BaseDialog {
    @BindView(R.id.listView)
    ListView listView;
    Lib_BaseAdapter<Object> adapter;

    public BottomListDialog(@NonNull Context context) {
        super(context, R.style.lib_dialog_NoTitle);
        setContentView(R.layout.dialog_bottom_list);
        ButterKnife.bind(this);
        _setGravity(Gravity.BOTTOM);
        listView.setAdapter(adapter = new Lib_BaseAdapter<Object>() {

            @Override
            public View getView(LayoutInflater layoutInflater, Object s, int i, View view, ViewGroup viewGroup) {
                ViewHolder viewHolder = _getViewHolder(view, viewGroup, R.layout.item_list_select);
                viewHolder.setText(R.id.tv_name, String.valueOf(s));
                return viewHolder.rootView;
            }
        });
    }

    public BottomListDialog setData(List list, AdapterView.OnItemClickListener listener) {
        adapter._setItemToUpdate(list);
        listView.setOnItemClickListener(listener);
        return this;
    }

    @OnClick({R.id.tv_cancel})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }
}
